package cn.gs.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.gs.domain.Customer;
import cn.gs.domain.LinkMan;
import cn.gs.service.CustomerServiceImpl;
import cn.gs.service.LinkManService;
import cn.gs.service.LinkManServiceImpl;

@Component(value = "linkManAction")
@Scope(value = "prototype")
public class LinkManAction extends ActionSupport implements ModelDriven<LinkMan> {

	LinkMan linkMan = new LinkMan();
	@Resource(name = "linkManService")
	LinkManService linkManService;// =new LinkManService();sss
	private List<LinkMan> list;
	private String pageCount;
	private String page;
	private String pCount;
	private Customer customer;
	private long lkm_id;
	private String lkm_name;

	public String selectCustom() {
		List<Customer> list = linkManService.selectCustom();
		ActionContext.getContext().put("list", list);
		return "selCustomSuc";
	}
	public String add() {
		linkManService.add(linkMan);
		return "addSuc";		
	}
	
	
	public String paging() {
		if(page==null){
			page="1";
		}
		int i=Integer.valueOf(page);
		list = linkManService.paging(i);
		List l=linkManService.selectPageCount();
		pageCount=String.valueOf(l.get(0));
		int a=Integer.valueOf(pageCount) ;
		int b=0;
		if(a%3==0) {
			b=a/3;
		}else {
			b=a/3+1;
		}
		pCount =String.valueOf(b);
		ActionContext.getContext().put("pCount",pCount);
		ActionContext.getContext().put("pageCount",pageCount);
		return "pagSuc";	
	}
	
	public String selectById() {
		linkMan=	linkManService.selectByID(linkMan.getLkm_id());
		List<Customer> list = linkManService.selectCustom();
		ActionContext.getContext().put("list", list);
		ActionContext.getContext().put("linkMan",linkMan);
		return "selIdSuc";
	}
	
	public String delete() {
		linkManService.delete(linkMan.getLkm_id());
		return "delSuc";
	}
	
	public String update() {
		linkManService.update(linkMan);
		return "updSuc";
	}
	
	public String selName() {
	try {
			System.out.println("最外层："+linkMan.getLkm_name());
			list= linkManService.selName(linkMan.getLkm_name());
			System.out.println("外层"+list);
			return "selnamesuc";
		} catch (Exception e) {
			return "selnamedef";
		}		
	}
	
	
	
	
	
	

	public LinkMan getModel() {
		// TODO Auto-generated method stub
		return linkMan;
	}

	public List<LinkMan> getList() {
		return list;
	}

	public void setList(List<LinkMan> list) {
		this.list = list;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	public String getPageCount() {
		return pageCount;
	}
	public void setPageCount(String pageCount) {
		this.pageCount = pageCount;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public String getpCount() {
		return pCount;
	}
	public void setpCount(String pCount) {
		this.pCount = pCount;
	}
	public long getLkm_id() {
		return lkm_id;
	}
	public void setLkm_id(long lkm_id) {
		this.lkm_id = lkm_id;
	}
	public String getLkm_name() {
		return lkm_name;
	}
	public void setLkm_name(String lkm_name) {
		this.lkm_name = lkm_name;
	}
	
	

}
